<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>后台登录-X-admin2.2</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/login.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
</head>
<body class="login-bg">

<div class="login layui-anim layui-anim-up">
    <div class="message">通用管理系统</div>
    <div id="darkbannerwrap"></div>

    <div >
        <input id="username" name="username" placeholder="用户名" type="text" lay-verify="required" class="layui-input">
        <hr class="hr15">
        <input id="password" name="password" lay-verify="required" placeholder="密码" type="password" class="layui-input">
        <hr class="hr15">
        <div>
            <input id="rememberMe" name="rememberMe" type="checkbox" title="记住我">
            <span>记住我</span>
        </div>
        <hr class="hr20">
        <input id="btnLogin"  value="登录"  style="width:100%;" type="button">
        <hr class="hr20">
    </div>
</div>

<script th:inline="javascript"> var ctx = [[@{/}]] </script>
<script>

    // 解决 frameset 出现登录的界面
    if (top.location != self.location){
        top.location=self.location;
    }

    $(function () {
        layui.use('form', function () {
            // var form = layui.form;
            // form.render();
            $('#btnLogin').click(function () {
                let userName = $('#username').val();
                let Password = $('#password').val();
                let rememberMe= $("input:checkbox:checked").val()

                $.ajax(
                    {
                        url: "/loginIn",
                        type: "post",
                        data: {
                            "username": userName,
                            "password": Password,
                            "rememberMe":rememberMe
                        },
                        success: function (_data) {
                            console.log("登录返回信息"+ JSON.stringify(_data))
                            if (_data.code == 0) {
                                console.log('进入成功显示页面');
                                layer.msg("登录成功");
                                location.href = '/index';
                            } else {
                                layer.msg("登录失败："+_data.msg);
                            }
                        },
                        error: function (_error) {
                            layer.msg("返回错误信息");
                        }
                    }
                );

            });

        })
    });

</script>
</body>
</html>